/**
 * ReporterAction.java
 * 2008-3-21
 * 作者 Administrator
 */
package org.jackysoft.struts2.business;

import java.util.Collection;

import javax.annotation.Resource;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.data.JRXmlDataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.jackysoft.entity.ArmMonthProductReporter;
import org.jackysoft.service.ArmMonthlyQuicklyReporterService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.w3c.dom.Document;

/**
 * @author qujiakang 军品月产量月快报
 */
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Results({ @Result(name = "success", type = "redirectAction", params = {
		"actionName", "arm-month-product-reporter" }) })
@Namespace("/armmonthreporter")
public class ArmMonthProductReporterAction extends
		ReporterCRUDAction<ArmMonthProductReporter> {

	static final Log logger = LogFactory
			.getLog(ArmMonthProductReporterAction.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = -1086907142135274965L;
	private ArmMonthProductReporter bean;
	private ArmMonthlyQuicklyReporterService service;
	private Collection<ArmMonthProductReporter> beans;

	// GET /arm-month-product-reporter/1
	public String show() {
		bean = service.get(getBean().getId());
		return "show";
	}

	// GET /arm-month-product-reporter

	public String execute() {
		return "index";
	}

	public String preSelected() throws Exception {
		bean = service.prepareSelect(DateTime.now());
		return "preSelected";
	}

	public String submit() throws Exception{
		service.submit(bean,isFinished());
		return "submit";
	}
	
	
	@Override
	public JRDataSource getJrDataSource() throws JRException {
		Document doc = service.w3cDocmentDataSource(getBean().getId());
		JRXmlDataSource jds = new JRXmlDataSource(doc);
		this.jrDataSource = jds;
		return jds;
	}

	public ArmMonthlyQuicklyReporterService getService() {
		return service;
	}

	@Resource
	public void setService(ArmMonthlyQuicklyReporterService service) {
		this.service = service;
		this.setDataProvider(service);
	}

	public Collection<ArmMonthProductReporter> getBeans() {
		return beans;
	}

	public void setBeans(Collection<ArmMonthProductReporter> beans) {
		this.beans = beans;
	}

	public ArmMonthProductReporter getBean() {
		return bean;
	}

	public void setBean(ArmMonthProductReporter bean) {
		this.bean = bean;
	}
}
